<script>
import {Toast} from "vant";

export default {
  name: "WWorkOrderChuliView",
  data() {
    return {
      fileList: [],
      formData: {},
      list: [],
      wxjl: "",
    }
  },
  methods: {
    onBack() {
      this.$router.go(-1);
    },
    fanhui() {
      this.list.wxjl = this.wxjl;
      this.list.url = (this.image.split(",")).join(",");
      console.log(this.list.url)
      this.list.status = 2;
      this.axios.post(`http://localhost:9999/api-work-order-service/work-order/save`, this.list).then(res => {
        if (res.data.code == 1) {
          Toast.success('处理成功');
          this.$router.push({path: '/wo-de'})
        } else {
          Toast.fail('处理失败');
        }
      })
      // this.$router.push({path: '/wo-de'})
    },
    read(file) {
      const files = Array.isArray(file) ? file : [file];
      files.forEach((item) => {
        // 创建 FormData
        const formData = new FormData();
        formData.append('file', item.file);
        // 上传文件到服务器
        this.axios.post('http://localhost:9999/api-work-order-service/oss/upload', formData, {
          headers: {
            // 设置请求头
            'Content-Type': 'multipart/form-data',
          },
        }).then(res => {
          // 初始化 shippingannex 为字符串
          if (!this.formData.shippingannex) {
            this.formData.shippingannex = '';
          }
          // 将文件 URL 添加到字符串中，用逗号分隔
          this.formData.shippingannex = this.formData.shippingannex
              ? this.formData.shippingannex + ',' + res.data
              : res.data;
          this.image = this.formData.shippingannex;
          console.log(this.image);
          console.log("2222" + this.image)
          Toast.success('文件上传成功');
        })
      });
    },
  },
  created() {
    // 获取参数
    this.id = this.$route.query.id
    // 查询
    this.axios.get(`http://localhost:9999/api-work-order-service/work-order/findById?id=` + this.id).then(res => {
      this.list = res.data.data;
      // console.log(res)
      // console.log(this.list)
    })
  }
}
</script>

<template>
<div>
  <!-- 顶部导航栏 -->
  <van-nav-bar
      title="处理"
      left-arrow
      @click-left="onBack"
      fixed
  />
    <div>
    <h4>维修记录</h4>
    <van-cell-group>
      <van-field v-model="wxjl" label="" placeholder="请在维修后输入详情..." />
    </van-cell-group>
  </div>
  <div>
<!--    <h4>上传图片/视频</h4>-->
    <div style="margin-top: 20px">
      <p style="margin-left: -250px;margin-bottom: 10px;">上传附件</p>
      <van-uploader v-model="fileList" :after-read="read" multiple :max-count="6"/>
    </div>
  </div>
  <van-button type="info" size="normal" @click="onBack">取消</van-button>
<!--  <van-button type="info" size="normal" @click="">保存</van-button>-->
  <van-button type="info" size="normal" @click="fanhui">确定</van-button>
</div>
</template>

<style scoped>

</style>